<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>02、GitLab | 小阳爱技术</title>
    <meta name="generator" content="VuePress 1.9.5">
    <link rel="icon" href="/img/favicon.ico">
    <link rel="icon" href="/favicon.ico">
    <link rel="manifest" href="/manifest.json">
    <meta name="description" content="Python, Linux, Nginx, Django, Flask, WEB, 前端, Java 全栈知识体系, java体系, java知识体系, java框架,java详解,java学习路线,java spring, java面试, 知识体系, java技术体系, java编程, java编程指南,java开发体系, java开发,java教程,java,java数据结构, 算法, 开发基础">
    <meta name="keywords" content="Python, Linux, Nginx, Django, Flask, WEB, 前端, Java 全栈知识体系, java体系, java知识体系, java框架,java详解,java学习路线,java spring, java面试, 知识体系, java技术体系, java编程, java编程指南,java开发体系, java开发,java教程,java,java数据结构, 算法, 开发基础">
    <meta name="theme-color" content="#11a8cd">
    <meta name="robots" content="all">
    <meta name="author" content="小阳爱技术">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    
    <link rel="preload" href="/assets/css/0.styles.8cb71cba.css" as="style"><link rel="preload" href="/assets/js/app.9f33dad1.js" as="script"><link rel="preload" href="/assets/js/2.336839c5.js" as="script"><link rel="preload" href="/assets/js/26.51a93ad7.js" as="script"><link rel="prefetch" href="/assets/js/10.78490e0e.js"><link rel="prefetch" href="/assets/js/11.358c0655.js"><link rel="prefetch" href="/assets/js/12.3d907ab6.js"><link rel="prefetch" href="/assets/js/13.e005782a.js"><link rel="prefetch" href="/assets/js/14.5c1831ed.js"><link rel="prefetch" href="/assets/js/15.3dae17f7.js"><link rel="prefetch" href="/assets/js/16.caf002bb.js"><link rel="prefetch" href="/assets/js/17.96d97c18.js"><link rel="prefetch" href="/assets/js/18.6f49a065.js"><link rel="prefetch" href="/assets/js/19.a72a1b44.js"><link rel="prefetch" href="/assets/js/20.5dbbd998.js"><link rel="prefetch" href="/assets/js/21.3b5c9825.js"><link rel="prefetch" href="/assets/js/22.588d1d79.js"><link rel="prefetch" href="/assets/js/23.bb2ba1d1.js"><link rel="prefetch" href="/assets/js/24.2036f1ef.js"><link rel="prefetch" href="/assets/js/25.7b40ded3.js"><link rel="prefetch" href="/assets/js/27.23a56743.js"><link rel="prefetch" href="/assets/js/28.2bfb83a2.js"><link rel="prefetch" href="/assets/js/29.b8c6cf94.js"><link rel="prefetch" href="/assets/js/3.00f81f09.js"><link rel="prefetch" href="/assets/js/30.fe19a5d5.js"><link rel="prefetch" href="/assets/js/31.b68040bb.js"><link rel="prefetch" href="/assets/js/32.d9d3dba8.js"><link rel="prefetch" href="/assets/js/33.59561c54.js"><link rel="prefetch" href="/assets/js/34.243786a2.js"><link rel="prefetch" href="/assets/js/35.daf1b05e.js"><link rel="prefetch" href="/assets/js/36.13258281.js"><link rel="prefetch" href="/assets/js/37.4b591e31.js"><link rel="prefetch" href="/assets/js/38.13d6ce06.js"><link rel="prefetch" href="/assets/js/39.c51dd517.js"><link rel="prefetch" href="/assets/js/4.72262f85.js"><link rel="prefetch" href="/assets/js/40.227cf12d.js"><link rel="prefetch" href="/assets/js/41.8ada8611.js"><link rel="prefetch" href="/assets/js/42.b168f326.js"><link rel="prefetch" href="/assets/js/43.9df968fc.js"><link rel="prefetch" href="/assets/js/44.1546c9b1.js"><link rel="prefetch" href="/assets/js/45.c29bc1da.js"><link rel="prefetch" href="/assets/js/46.2de30989.js"><link rel="prefetch" href="/assets/js/47.34b5ca9a.js"><link rel="prefetch" href="/assets/js/5.56d0fbc7.js"><link rel="prefetch" href="/assets/js/6.b9ff2c2e.js"><link rel="prefetch" href="/assets/js/7.41c828d4.js"><link rel="prefetch" href="/assets/js/8.82412463.js"><link rel="prefetch" href="/assets/js/9.c499cdfa.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8cb71cba.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="小阳爱技术" class="logo"> <span class="site-name can-hide">小阳爱技术</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Python" class="dropdown-title"><a href="/python" class="link-title">Python</a> <span class="title" style="display:none;">Python</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/fb2fff/404" class="nav-link">暂无</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="DevOPs" class="dropdown-title"><a href="/devops/" class="link-title">DevOPs</a> <span class="title" style="display:none;">DevOPs</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>Git</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Git核心命令</a></li></ul></li><li class="dropdown-item"><h4>GitLab</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Gitlab基础</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">CI/CD语法</a></li></ul></li><li class="dropdown-item"><h4>Jernkins</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Jenkins入门</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Pipeline流水线语法</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Jenkins集成各种工具</a></li></ul></li><li class="dropdown-item"><h4>企业级流水线案例</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">企业级流水线的两个场景</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Npm企业流水线案例</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Java企业级流水线案例</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Python企业级流水线案例</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Golang企业级流水线案例</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><a href="/more/" class="link-title">更多</a> <span class="title" style="display:none;">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/f2a556/" class="nav-link">学习</a></li><li class="dropdown-item"><!----> <a href="/pages/aea6571b7a8bae86/" class="nav-link">面试</a></li><li class="dropdown-item"><!----> <a href="/pages/2d615df9a36a98ed/" class="nav-link">心情杂货</a></li><li class="dropdown-item"><!----> <a href="/pages/baaa02/" class="nav-link">实用技巧</a></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">关于</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="收藏" class="dropdown-title"><a href="/pages/beb6c0bd8a66cea6/" class="link-title">收藏</a> <span class="title" style="display:none;">收藏</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/beb6c0bd8a66cea6/" class="nav-link">网站</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com//" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="/img/logo.png"> <div class="blogger-info"><h3>小阳爱技术</h3> <span>数据库管理员 &amp;&amp; 容器云狂热分子</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Python" class="dropdown-title"><a href="/python" class="link-title">Python</a> <span class="title" style="display:none;">Python</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/fb2fff/404" class="nav-link">暂无</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="DevOPs" class="dropdown-title"><a href="/devops/" class="link-title">DevOPs</a> <span class="title" style="display:none;">DevOPs</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>Git</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Git核心命令</a></li></ul></li><li class="dropdown-item"><h4>GitLab</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Gitlab基础</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">CI/CD语法</a></li></ul></li><li class="dropdown-item"><h4>Jernkins</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Jenkins入门</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Pipeline流水线语法</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Jenkins集成各种工具</a></li></ul></li><li class="dropdown-item"><h4>企业级流水线案例</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">企业级流水线的两个场景</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Npm企业流水线案例</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Java企业级流水线案例</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Python企业级流水线案例</a></li><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">Golang企业级流水线案例</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><a href="/more/" class="link-title">更多</a> <span class="title" style="display:none;">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/f2a556/" class="nav-link">学习</a></li><li class="dropdown-item"><!----> <a href="/pages/aea6571b7a8bae86/" class="nav-link">面试</a></li><li class="dropdown-item"><!----> <a href="/pages/2d615df9a36a98ed/" class="nav-link">心情杂货</a></li><li class="dropdown-item"><!----> <a href="/pages/baaa02/" class="nav-link">实用技巧</a></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">关于</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="收藏" class="dropdown-title"><a href="/pages/beb6c0bd8a66cea6/" class="link-title">收藏</a> <span class="title" style="display:none;">收藏</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/beb6c0bd8a66cea6/" class="nav-link">网站</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com//" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>git</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>gitlab</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/fb2fff/" aria-current="page" class="active sidebar-link">02、GitLab</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/fb2fff/#gitlab-安装" class="sidebar-link">GitLab 安装</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/fb2fff/#安装相关依赖" class="sidebar-link">安装相关依赖</a></li><li class="sidebar-sub-header level3"><a href="/pages/fb2fff/#添加gitlab包仓库并安装包" class="sidebar-link">添加GitLab包仓库并安装包</a></li><li class="sidebar-sub-header level3"><a href="/pages/fb2fff/#部署ssl证书" class="sidebar-link">部署SSL证书</a></li><li class="sidebar-sub-header level3"><a href="/pages/fb2fff/#配置-gitlab-并启动" class="sidebar-link">配置 GitLab 并启动</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#配置-nginx" class="sidebar-link">配置 Nginx</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#重定向-http-请求到-https" class="sidebar-link">重定向 HTTP 请求到 HTTPS</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#安装nginx证书" class="sidebar-link">安装Nginx证书</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#自定义错误页面" class="sidebar-link">自定义错误页面</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#刷新配置" class="sidebar-link">刷新配置</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#启动gitlab" class="sidebar-link">启动Gitlab</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#登录gitlab" class="sidebar-link">登录Gitlab</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/fb2fff/#配置-gitlab-的邮件服务" class="sidebar-link">配置 GitLab 的邮件服务</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#申请163邮箱的客户端密码" class="sidebar-link">申请163邮箱的客户端密码</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#创建-gitlab-密码-secret" class="sidebar-link">创建 GitLab 密码 secret</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#添加-stmp-配置" class="sidebar-link">添加 STMP 配置</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#测试-stmp-服务" class="sidebar-link">测试 STMP 服务</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/fb2fff/#gitlab-用户管理" class="sidebar-link">GitLab 用户管理</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/fb2fff/#创建用户组" class="sidebar-link">创建用户组</a></li><li class="sidebar-sub-header level3"><a href="/pages/fb2fff/#创建用户" class="sidebar-link">创建用户</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/fb2fff/#gitlab-新建项目" class="sidebar-link">Gitlab 新建项目</a></li><li class="sidebar-sub-header level2"><a href="/pages/fb2fff/#gitlab-runner" class="sidebar-link">GitLab Runner</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#安装-gitlab-runner" class="sidebar-link">安装 gitlab-runner</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#注册-gitlab-runner" class="sidebar-link">注册 Gitlab-runner</a></li><li class="sidebar-sub-header level5"><a href="/pages/fb2fff/#gitlab-runner-类型" class="sidebar-link">gitlab-runner 类型</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#gitlab-runner-服务管理" class="sidebar-link">gitlab-runner 服务管理</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/fb2fff/#gitlab-ci-cd-语法" class="sidebar-link">Gitlab Ci/CD 语法</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/fb2fff/#pipeline核心语法" class="sidebar-link">Pipeline核心语法</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#stages-阶段控制" class="sidebar-link">stages 阶段控制</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#variables-环境变量" class="sidebar-link">variables 环境变量</a></li><li class="sidebar-sub-header level4"><a href="/pages/fb2fff/#job-作业" class="sidebar-link">Job 作业</a></li><li class="sidebar-sub-header level5"><a href="/pages/fb2fff/#修改-gitlab-runner-配置文件" class="sidebar-link">修改 gitlab-runner 配置文件</a></li><li class="sidebar-sub-header level6"><a href="/pages/fb2fff/#修改配置文件" class="sidebar-link">修改配置文件</a></li><li class="sidebar-sub-header level5"><a href="/pages/fb2fff/#parallel-并行运行" class="sidebar-link">parallel 并行运行</a></li><li class="sidebar-sub-header level5"><a href="/pages/fb2fff/#needs-依赖运行" class="sidebar-link">needs 依赖运行</a></li><li class="sidebar-sub-header level5"><a href="/pages/fb2fff/#rules-流程控制" class="sidebar-link">rules 流程控制</a></li></ul></li></ul></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>jenkins</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>企业级流水线</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>自动化测试流水线</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><a href="/categories/?category=DevOps" title="分类" data-v-06225672>DevOps</a></li><li data-v-06225672><a href="/categories/?category=gitlab" title="分类" data-v-06225672>gitlab</a></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://blog.abck8s.com" target="_blank" title="作者" class="beLink" data-v-06225672>小阳爱技术</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2022-06-22</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">02、GitLab<!----></h1>  <div class="theme-vdoing-content content__default"><h1 id="gitlab"><a href="#gitlab" class="header-anchor">#</a> GitLab</h1> <p><img src="/img/image-20220618164538957.png" alt="image-20220618164538957"></p> <p>官网： https://about.gitlab.com/</p> <p>GitLab 是一个用于仓库管理系统的开源项目，使用Git作为代码管理工具，并在此基础上搭建起来的 web服务。</p> <p>GitLab和GitHub一样属于第三方基于Git开发的作品，免费且开源（基于MIT协议），与Github类似， 可以注册用户，任意提交你的代码，添加SSHKey等等。不同的是，GitLab是可以部署到自己的服务器 上，数据库等一切信息都掌握在自己手上，适合团队内部协作开发，你总不可能把团队内部的智慧总放 在别人的服务器上吧？简单来说可把GitLab看作个人版的GitHub。</p> <h2 id="gitlab-安装"><a href="#gitlab-安装" class="header-anchor">#</a> GitLab 安装</h2> <blockquote><p>Gitlab有两个版本，一个社区版另一个是企业版。通常的企业中使用社区版的功能已经够用了，本次选用的也是 GitLab 社区版。</p> <p>安装文档URL：https://about.gitlab.com/install/?version=ce</p></blockquote> <h3 id="安装相关依赖"><a href="#安装相关依赖" class="header-anchor">#</a> 安装相关依赖</h3> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">sudo</span> yum <span class="token function">install</span> -y <span class="token function">curl</span> policycoreutils-python openssh-server perl postfix
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>Postfix 以发送通知电子邮件，通常我们需要将其设置成开机自启动。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ systemctl <span class="token builtin class-name">enable</span> --now postfix
Created symlink from /etc/systemd/system/multi-user.target.wants/postfix.service to /usr/lib/systemd/system/postfix.service.
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="添加gitlab包仓库并安装包"><a href="#添加gitlab包仓库并安装包" class="header-anchor">#</a> 添加GitLab包仓库并安装包</h3> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">curl</span> https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh <span class="token operator">|</span> <span class="token function">sudo</span> <span class="token function">bash</span>

$ yum <span class="token function">install</span> gitlab-ce -y
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>但是这里的gitlab下载比较慢。我们可以选择国内的镜像进行下载。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">wget</span> https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.0.3-ce.0.el7.x86_64.rpm

$ yum <span class="token function">install</span> gitlab-ce -y
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="部署ssl证书"><a href="#部署ssl证书" class="header-anchor">#</a> 部署SSL证书</h3> <p>如果我们需要在使用 gitlab 的时候，通常需要用到 HTTPS，这个时候我们需要提前部署好SSL证书。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">mkdir</span> /etc/gitlab/ssl
$ <span class="token function">chmod</span> <span class="token number">755</span> /etc/gitlab/ssl
$ ll /etc/gitlab/ssl
total <span class="token number">16</span>
-rw-r--r-- <span class="token number">1</span> root root <span class="token number">3905</span> Jun <span class="token number">18</span> <span class="token number">16</span>:59 gitlab.abck8s.com.crt
-rw-r--r-- <span class="token number">1</span> root root <span class="token number">1010</span> Jun <span class="token number">18</span> <span class="token number">16</span>:59 gitlab.abck8s.com.csr
-rw-r--r-- <span class="token number">1</span> root root <span class="token number">1704</span> Jun <span class="token number">18</span> <span class="token number">16</span>:59 gitlab.abck8s.com.key
-rw-r--r-- <span class="token number">1</span> root root <span class="token number">3905</span> Jun <span class="token number">18</span> <span class="token number">16</span>:59 gitlab.abck8s.com.pem
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h3 id="配置-gitlab-并启动"><a href="#配置-gitlab-并启动" class="header-anchor">#</a> 配置 GitLab 并启动</h3> <p>在启动 Gitlab 之前，需要配置一下 Gitlab。</p> <h4 id="配置-nginx"><a href="#配置-nginx" class="header-anchor">#</a> 配置 Nginx</h4> <blockquote><p>Nginx配置文档：https://docs.gitlab.cn/omnibus/settings/nginx.html</p></blockquote> <p>默认情况下，Omnibus GitLab 不使用 HTTPS。</p> <p>为域 <code>gitlab.abck8s.com</code> 启用 HTTPS 的步骤如下：</p> <ol><li><p>在 <code>/etc/gitlab/gitlab.rb</code> 中编辑 <code>external_url</code>：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>external_url <span class="token string">&quot;https://gitlab.abck8s.com&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></li> <li><p>在 <code>/etc/gitlab/gitlab.rb</code> 中禁用 Let’s Encrypt。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>letsencrypt<span class="token punctuation">[</span><span class="token string">'enable'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">false</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></li></ol> <h4 id="重定向-http-请求到-https"><a href="#重定向-http-请求到-https" class="header-anchor">#</a> 重定向 <code>HTTP</code> 请求到 <code>HTTPS</code></h4> <p>默认情况下，您指定的 <code>external_url</code> 以 ‘https’ 开头时，NGINX 将不会再在 80 端口监听未加密的 HTTP 流量。如果您想要将所有 HTTP 流量重定向到 HTTPS，您可以使用 <code>redirect_http_to_https</code> 设置。</p> <p>使用 Let’s Encrypt 时，默认情况下启用该操作。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>external_url <span class="token string">&quot;https://gitlab.example.com&quot;</span>
nginx<span class="token punctuation">[</span><span class="token string">'redirect_http_to_https'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">true</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h4 id="安装nginx证书"><a href="#安装nginx证书" class="header-anchor">#</a> 安装Nginx证书</h4> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>nginx<span class="token punctuation">[</span><span class="token string">'ssl_certificate'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;/etc/gitlab/ssl/gitlab.abck8s.com.crt&quot;</span>
nginx<span class="token punctuation">[</span><span class="token string">'ssl_certificate_key'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;/etc/gitlab/ssl/gitlab.abck8s.com.key&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h4 id="自定义错误页面"><a href="#自定义错误页面" class="header-anchor">#</a> 自定义错误页面</h4> <p>设置自定义错误页面主要是当 Gitlab 出现问题的时候，设置一下提示信息。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>nginx<span class="token punctuation">[</span><span class="token string">'custom_error_pages'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token string">'404'</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token punctuation">{</span>
    <span class="token string">'title'</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token string">'There is a temporary problem with gitlab'</span>,
    <span class="token string">'header'</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token string">'Example header'</span>,
    <span class="token string">'message'</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token string">'Example message'</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h4 id="刷新配置"><a href="#刷新配置" class="header-anchor">#</a> 刷新配置</h4> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ gitlab-ctl reconfigure
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="启动gitlab"><a href="#启动gitlab" class="header-anchor">#</a> 启动Gitlab</h4> <blockquote><p>第一次刷新配置，自动启动。</p></blockquote> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ gitlab-ctl start
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="登录gitlab"><a href="#登录gitlab" class="header-anchor">#</a> 登录Gitlab</h4> <p><img src="/img/image-20220619083537940.png" alt="image-20220619083537940"></p> <p>默认用户名为：root</p> <p>默认密码在：/etc/gitlab/initial_root_password</p> <p><img src="/img/image-20220619083637613.png" alt="image-20220619083637613"></p> <p>登录成功之后，首先修改默认的密码，这是因为默认的密码有效期只有24小时。</p> <p><img src="/img/image-20220619083840835.png" alt="image-20220619083840835"></p> <p><img src="/img/image-20220619083910303.png" alt="image-20220619083910303"></p> <p><img src="/img/image-20220619083952160.png" alt="image-20220619083952160"></p> <h2 id="配置-gitlab-的邮件服务"><a href="#配置-gitlab-的邮件服务" class="header-anchor">#</a> 配置 GitLab 的邮件服务</h2> <p>Gitlab 是一个多用户的代码托管平台，为了安全起见，通常所有的任务都需要使用到邮件服务。这里我们采用免费的 163 邮箱为例。</p> <blockquote><p>文档地址：https://docs.gitlab.cn/omnibus/settings/smtp.html#netease-free-enterprise-email</p></blockquote> <h4 id="申请163邮箱的客户端密码"><a href="#申请163邮箱的客户端密码" class="header-anchor">#</a> 申请163邮箱的客户端密码</h4> <p><img src="/img/image-20220619084704310.png" alt="image-20220619084704310"></p> <p><img src="/img/image-20220619084812811.png" alt="image-20220619084812811"></p> <h4 id="创建-gitlab-密码-secret"><a href="#创建-gitlab-密码-secret" class="header-anchor">#</a> 创建 GitLab 密码 secret</h4> <p>配置邮件在GitLab中有两种方式，一种是明文另一种就是密文。明文比较简单，直接修改<code>/etc/gitlab/gitlab.rb</code>即可，但是这种做法很不安全；于是GitLab为我们提供了另一个加密的Secret的方式。</p> <ol><li>编辑加密的 secret</li></ol> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">sudo</span> gitlab-rake gitlab:smtp:secret:edit <span class="token assign-left variable">EDITOR</span><span class="token operator">=</span>vim
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ol start="2"><li>SMTP secret 的未加密内容应输入如下：</li></ol> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>user_name: <span class="token string">'smtp user'</span>
password: <span class="token string">'smtp password'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ol start="3"><li>编辑 <code>/etc/gitlab/gitlab.rb</code> 并删除 <code>smtp_user_name</code> 和 <code>smtp_password</code> 的设置。</li></ol> <h4 id="添加-stmp-配置"><a href="#添加-stmp-配置" class="header-anchor">#</a> 添加 STMP 配置</h4> <p>将 SMTP 配置打开。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">cat</span> /etc/gitlab/gitlab.rb <span class="token operator">|</span> <span class="token function">grep</span> -Ev <span class="token string">'^#|^$'</span>
gitlab_rails<span class="token punctuation">[</span><span class="token string">'smtp_enable'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">true</span>
gitlab_rails<span class="token punctuation">[</span><span class="token string">'smtp_address'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;smtp.163.com&quot;</span>
gitlab_rails<span class="token punctuation">[</span><span class="token string">'smtp_port'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">465</span>
gitlab_rails<span class="token punctuation">[</span><span class="token string">'smtp_domain'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;163.com&quot;</span>
gitlab_rails<span class="token punctuation">[</span><span class="token string">'smtp_authentication'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;login&quot;</span>
gitlab_rails<span class="token punctuation">[</span><span class="token string">'smtp_enable_starttls_auto'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">true</span>
gitlab_rails<span class="token punctuation">[</span><span class="token string">'smtp_tls'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">true</span>
gitlab_rails<span class="token punctuation">[</span><span class="token string">'smtp_pool'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">true</span>
gitlab_rails<span class="token punctuation">[</span><span class="token string">'gitlab_email_from'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'chenyangqit@163.com'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p>修改完成之后，需要重新执行<code>sudo gitlab-ctl reconfigure</code>重新生成配置。</p> <h4 id="测试-stmp-服务"><a href="#测试-stmp-服务" class="header-anchor">#</a> 测试 STMP 服务</h4> <p>您可以使用 Rails 控制台验证是否可以正确发送电子邮件。 在 GitLab 服务器上，执行<code>gitlab-rails console</code>命令进入控制台。然后，您可以在控制台提示符下输入以下命令，以使系统发送测试电子邮件：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>Notify.test_email<span class="token punctuation">(</span><span class="token string">'chenyangqit@163.com'</span>, <span class="token string">'邮件主题'</span>, <span class="token string">'邮件内容'</span><span class="token punctuation">)</span>.deliver_now
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><img src="/img/image-20220619092000051.png" alt="image-20220619092000051"></p> <p>测试成功。</p> <h2 id="gitlab-用户管理"><a href="#gitlab-用户管理" class="header-anchor">#</a> GitLab 用户管理</h2> <p>在 GitLab 中，用户主要分为用户组和用户两个概念。用户组包含用户，这样做有利于设置用户统一管理用户。</p> <h3 id="创建用户组"><a href="#创建用户组" class="header-anchor">#</a> 创建用户组</h3> <p><img src="/img/image-20220619094524701.png" alt="image-20220619094524701"></p> <p><img src="/img/image-20220619094558649.png" alt="image-20220619094558649"></p> <p><img src="/img/image-20220619094735537.png" alt="image-20220619094735537"></p> <p><img src="/img/image-20220619094821440.png" alt="image-20220619094821440"></p> <h3 id="创建用户"><a href="#创建用户" class="header-anchor">#</a> 创建用户</h3> <p><img src="/img/image-20220619095246995.png" alt="image-20220619095246995"></p> <p><img src="/img/image-20220619095347302.png" alt="image-20220619095347302"></p> <p>创建完毕之后，该用户会收到一份注册邮件</p> <p><img src="/img/image-20220619095534751.png" alt="image-20220619095534751"></p> <p><img src="/img/image-20220619095552617.png" alt="image-20220619095552617"></p> <h2 id="gitlab-新建项目"><a href="#gitlab-新建项目" class="header-anchor">#</a> Gitlab 新建项目</h2> <p><img src="/img/image-20220619162124187.png" alt="image-20220619162124187"></p> <p><img src="/img/image-20220619162139831.png" alt="image-20220619162139831"></p> <p><img src="/img/image-20220619162235991.png" alt="image-20220619162235991"></p> <h2 id="gitlab-runner"><a href="#gitlab-runner" class="header-anchor">#</a> GitLab Runner</h2> <p><code>GitLab-Runner</code>是配合<code>GitLab-CI</code>进行使用的。一般地，GitLab里面的每一个工程都会定义一个属于这个工程的软件集成脚本，用来自动化地完成一些软件集成工作。当这个工程的仓库代码发生变动时，比如有人push了代码，GitLab就会将这个变动通知GitLab-CI。这时GitLab-CI会找出与这个工程相关联的Runner，并通知这些Runner把代码更新到本地并执行预定义好的执行脚本。</p> <blockquote><p>文档地址：https://docs.gitlab.com/runner/install/linux-manually.html</p></blockquote> <h4 id="安装-gitlab-runner"><a href="#安装-gitlab-runner" class="header-anchor">#</a> 安装 gitlab-runner</h4> <p>由于兼容性原因，GitLab Runner 的 <code>主版本.小版本</code> 应和极狐GitLab 的 <code>主版本.小版本</code> 保持同步。老版本的 GitLab Runner 可能适用于新版本的极狐 GitLab，反之亦然。但是如果存在版本差异，功能特性可能不可用或无法正常工作。</p> <p>在小版本更新之间保证向后兼容。但是有时小版本更新会引入要求 GitLab Runner 处于相同版本的新特性功能。</p> <p>我当前使用的的 <code>Gitlab</code> 版本是 <code>15.0.0</code>，所以<code>girlab-runner</code>我们同样选用<code>15.0.0</code>，同时为了提高下载速度，我们直接在<a href="https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/" target="_blank" rel="noopener noreferrer">清华大学开源镜像站<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>中下载。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">wget</span> https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-15.0.0-1.x86_64.rpm
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>安装</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ yum <span class="token function">install</span> gitlab-runner-15.0.0-1.x86_64.rpm -y
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>启动</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ gitlab-runner start 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>查看启动状态</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ gitlab-runner status 
Runtime platform                                    <span class="token assign-left variable">arch</span><span class="token operator">=</span>amd64 <span class="token assign-left variable">os</span><span class="token operator">=</span>linux <span class="token assign-left variable">pid</span><span class="token operator">=</span><span class="token number">30587</span> <span class="token assign-left variable">revision</span><span class="token operator">=</span>febb2a09 <span class="token assign-left variable">version</span><span class="token operator">=</span><span class="token number">15.0</span>.0
gitlab-runner: Service is running
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h4 id="注册-gitlab-runner"><a href="#注册-gitlab-runner" class="header-anchor">#</a> 注册 Gitlab-runner</h4> <p>安装 <code>gitlab-runner</code> 之后，如果想用 Gitlab 来调用 gitlab-runner ，还需要注册 gitlab-runner 服务。</p> <h5 id="gitlab-runner-类型"><a href="#gitlab-runner-类型" class="header-anchor">#</a> gitlab-runner 类型</h5> <p>不同的 gitlab-runner 类型，能够运行不同的任务。</p> <ul><li>shared ： 运行整个平台项目的作业（gitlab）</li> <li>group： 运行特定group下的所有项目的作业（group）</li> <li>specific: 运行指定的项目作业（project）</li> <li>locked： 无法运行项目作业</li> <li>paused： 不会运行作业</li></ul> <p><img src="/img/image-20220619131301453.png" alt="image-20220619131301453"></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ gitlab-runner register
Runtime platform                                    <span class="token assign-left variable">arch</span><span class="token operator">=</span>amd64 <span class="token assign-left variable">os</span><span class="token operator">=</span>linux <span class="token assign-left variable">pid</span><span class="token operator">=</span><span class="token number">31549</span> <span class="token assign-left variable">revision</span><span class="token operator">=</span>febb2a09 <span class="token assign-left variable">version</span><span class="token operator">=</span><span class="token number">15.0</span>.0
Running <span class="token keyword">in</span> system-mode.                            
                                                   
Enter the GitLab instance URL <span class="token punctuation">(</span>for example, https://gitlab.com/<span class="token punctuation">)</span>:
https://gitlab.abck8s.com/
Enter the registration token:
1bkW7SdjDnkuk9adhf8f
Enter a description <span class="token keyword">for</span> the runner:
<span class="token punctuation">[</span>gitlab.abck8s.com<span class="token punctuation">]</span>: 
Enter tags <span class="token keyword">for</span> the runner <span class="token punctuation">(</span>comma-separated<span class="token punctuation">)</span>:
build,k8sbuild,go,java,python
Enter optional maintenance note <span class="token keyword">for</span> the runner:

Registering runner<span class="token punctuation">..</span>. succeeded                     <span class="token assign-left variable">runner</span><span class="token operator">=</span>1bkW7Sdj
Enter an executor: docker, docker-ssh+machine, kubernetes, virtualbox, docker+machine, custom, docker-ssh, parallels, shell, ssh:
shell
Runner registered successfully. Feel <span class="token function">free</span> to start it, but <span class="token keyword">if</span> it's running already the config should be automatically reloaded<span class="token operator">!</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><p><img src="/img/image-20220619131940643.png" alt="image-20220619131940643"></p> <h4 id="gitlab-runner-服务管理"><a href="#gitlab-runner-服务管理" class="header-anchor">#</a> gitlab-runner 服务管理</h4> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>gitlab-runner uninstall <span class="token comment">#该命令停止运行并从服务中卸载GitLab Runner。</span>
gitlab-runner start     <span class="token comment">#该命令启动GitLab Runner服务。</span>
gitlab-runner stop      <span class="token comment">#该命令停止GitLab Runner服务。</span>
gitlab-runner restart   <span class="token comment">#该命令将停止，然后启动GitLab Runner服务。</span>
gitlab-runner status 	<span class="token comment">#此命令显示GitLab Runner服务的状态。当服务正在运行时，退出代码为零；而当服务未运行时，退出代码为非零。</span>

gitlab-runner register  <span class="token comment">#默认交互模式下使用，非交互模式添加 --non-interactive</span>
gitlab-runner list      <span class="token comment">#此命令列出了保存在配置文件中的所有运行程序</span>
gitlab-runner verify    <span class="token comment">#此命令检查注册的runner是否可以连接，但不验证GitLab服务是否正在使用runner。 --delete 删除</span>
gitlab-runner unregister   <span class="token comment">#该命令使用GitLab取消已注册的runner。</span>

<span class="token comment">#使用令牌注销</span>
gitlab-runner unregister --url https://gitlab.abck8s.com/ --token 1bkW7SdjDnkuk9adhf8f

<span class="token comment">#使用名称注销（同名删除第一个）</span>
gitlab-runner unregister --name gitlab.abck8s.com

<span class="token comment">#注销所有</span>
gitlab-runner unregister --all-runners


gitlab-runner --debug <span class="token operator">&lt;</span>command<span class="token operator">&gt;</span>   	<span class="token comment">#调试模式排查错误特别有用。</span>
gitlab-runner <span class="token operator">&lt;</span>command<span class="token operator">&gt;</span> --help    	<span class="token comment">#获取帮助信息</span>
gitlab-runner run       			<span class="token comment">#普通用户模式  配置文件位置 ~/.gitlab-runner/config.toml</span>
<span class="token function">sudo</span> gitlab-runner run  			<span class="token comment"># 超级用户模式  配置文件位置/etc/gitlab-runner/config.toml</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><h2 id="gitlab-ci-cd-语法"><a href="#gitlab-ci-cd-语法" class="header-anchor">#</a> Gitlab Ci/CD 语法</h2> <p><strong>CI/CD</strong> 是 Gitlab 提供的一整套持续集成、持续交付解决方案。</p> <blockquote><p><strong>前提：服务器部署配置了 Runner 。</strong></p></blockquote> <p>每一个项目中，关于 <code>CI/CD</code> 的配置都是通过该项目根目录中名为<code>.gitlab-ci.yaml</code> 的 <strong>YAML</strong> 文件。</p> <h3 id="pipeline核心语法"><a href="#pipeline核心语法" class="header-anchor">#</a> Pipeline核心语法</h3> <p>在 <strong>pipeline</strong> 核心语法中，最主要的有三个部分，分别是 <strong>stages 阶段控制</strong>、<strong>variables 环境变量</strong> 和 <strong>Job</strong> 三个部分。</p> <h4 id="stages-阶段控制"><a href="#stages-阶段控制" class="header-anchor">#</a> stages 阶段控制</h4> <p>在 gitlab 中，一共可以分为三个阶段，分别是<strong>开始时阶段</strong>、<strong>自定义阶段</strong>和<strong>结束时阶段</strong>三个阶段。</p> <ul><li><strong>.pre阶段</strong>的作业总是在流水线<strong>开始时</strong>执行；</li> <li><strong>.post阶段</strong>的作业总是在流水线<strong>结束时</strong>执行；</li> <li>自定义阶段</li></ul> <p>案例：一个简单的流水线语法</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">stages</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token string">&quot;.pre&quot;</span>
  <span class="token punctuation">-</span> build
  <span class="token punctuation">-</span> test
  <span class="token punctuation">-</span> deploy
  <span class="token punctuation">-</span> <span class="token string">&quot;.post&quot;</span>

<span class="token key atrule">cipre</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> .pre
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;开始执行<span class="token punctuation">...</span>&quot;

<span class="token key atrule">cibuild</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;Build<span class="token punctuation">...</span>&quot;

<span class="token key atrule">citest</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> test
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span> 
    <span class="token punctuation">-</span> echo &quot;Test<span class="token punctuation">...</span>&quot;

<span class="token key atrule">cideploy</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> deploy
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span> 
    <span class="token punctuation">-</span> echo &quot;Deploy<span class="token punctuation">...</span>&quot;

<span class="token key atrule">ciinit</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> .post
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;Post<span class="token punctuation">...</span>&quot;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br></div></div><table><thead><tr><th><strong>语法关键字</strong></th> <th><strong>作用</strong></th></tr></thead> <tbody><tr><td>variables</td> <td>定义作业中的环境变量</td></tr> <tr><td>tags</td> <td>根据标签选择运行作业的构建节点</td></tr> <tr><td>stage</td> <td>指定当前作业所属的阶段名称</td></tr> <tr><td>script</td> <td>具体执行的命令</td></tr> <tr><td>before_script</td> <td>作业在<strong>运行前</strong>执行的Shell命令行</td></tr> <tr><td>after_script</td> <td>作业在<strong>运行后</strong>执行的Shell命令行</td></tr></tbody></table> <p><img src="/img/image-20220619171007237.png" alt="image-20220619171007237"></p> <h4 id="variables-环境变量"><a href="#variables-环境变量" class="header-anchor">#</a> variables 环境变量</h4> <p>变量可以分为全局变量和局部变量；全局变量是整个流水线可以用的，局部变量是仅在作业中生效的；</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">stages</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token string">&quot;.pre&quot;</span>
  <span class="token punctuation">-</span> build

<span class="token comment"># 全局变量</span>
<span class="token key atrule">variables</span><span class="token punctuation">:</span>
  <span class="token key atrule">TEST_ENV</span><span class="token punctuation">:</span> <span class="token string">&quot;TEST&quot;</span>

<span class="token key atrule">cipre</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> .pre
  <span class="token key atrule">variables</span><span class="token punctuation">:</span>
    <span class="token key atrule">TEST_ENV</span><span class="token punctuation">:</span> <span class="token string">&quot;PRE&quot;</span>
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;开始执行$<span class="token punctuation">{</span>TEST_ENV<span class="token punctuation">}</span><span class="token punctuation">...</span>&quot;

<span class="token key atrule">cibuild</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;开始执行$<span class="token punctuation">{</span>TEST_ENV<span class="token punctuation">}</span><span class="token punctuation">...</span>&quot;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><p><img src="/img/image-20220619171637295.png" alt="image-20220619171637295"></p> <p><img src="/img/image-20220619171715101.png" alt="image-20220619171715101"></p> <h4 id="job-作业"><a href="#job-作业" class="header-anchor">#</a> Job 作业</h4> <p>之前和之后运行。</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">stages</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token string">&quot;.pre&quot;</span>
  <span class="token punctuation">-</span> build

<span class="token key atrule">cipre</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> .pre
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">before_script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;before_script<span class="token punctuation">...</span>&quot;
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;script<span class="token punctuation">...</span>&quot;
  <span class="token key atrule">after_script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;after_script<span class="token punctuation">...</span>&quot;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><p><img src="/img/image-20220619174215867.png" alt="image-20220619174215867"></p> <p>通常，我们需要并行运行两个或者多个作业。</p> <p>这种情况我们可以将需要并行的的多个阶段的名称设置成一样</p> <blockquote><p>注意：流水线并行需要 gitlab-runner 支持，默认 gitlab-runner 只支持同时运行单个流水线。</p></blockquote> <h5 id="修改-gitlab-runner-配置文件"><a href="#修改-gitlab-runner-配置文件" class="header-anchor">#</a> 修改 gitlab-runner 配置文件</h5> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>$ <span class="token function">vim</span> /etc/gitlab-runner/config.toml 
concurrent <span class="token operator">=</span> <span class="token number">10</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h6 id="修改配置文件"><a href="#修改配置文件" class="header-anchor">#</a> 修改配置文件</h6> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">stages</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> build
  
<span class="token key atrule">cibuild</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;开始执行$<span class="token punctuation">{</span>TEST_ENV<span class="token punctuation">}</span><span class="token punctuation">...</span>&quot;

<span class="token key atrule">cibuild1</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;开始执行$<span class="token punctuation">{</span>TEST_ENV<span class="token punctuation">}</span><span class="token punctuation">...</span>&quot;

<span class="token key atrule">cibuild2</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;开始执行$<span class="token punctuation">{</span>TEST_ENV<span class="token punctuation">}</span><span class="token punctuation">...</span>&quot;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><p><img src="/img/image-20220620125042546.png" alt="image-20220620125042546"></p> <h5 id="parallel-并行运行"><a href="#parallel-并行运行" class="header-anchor">#</a> parallel 并行运行</h5> <p>通常，我们有这种情况，为了提高速率使用多线程的方式运行同一个程序。在流水线中同样如此，使用 parallel 能够并行运行。</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">stages</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> build
<span class="token key atrule">cipre</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;script<span class="token punctuation">...</span>&quot;
  <span class="token key atrule">parallel</span><span class="token punctuation">:</span> <span class="token number">3</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><img src="/img/image-20220620123820666.png" alt="image-20220620123820666"></p> <h5 id="needs-依赖运行"><a href="#needs-依赖运行" class="header-anchor">#</a> needs 依赖运行</h5> <p>通常，运行流水线有这样一个情况，分别是第一步运行完成之后，才能运行第二步；这种情况就需要用到依赖运行。</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">cibuild</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;开始执行$<span class="token punctuation">{</span>TEST_ENV<span class="token punctuation">}</span><span class="token punctuation">...</span>&quot;

<span class="token key atrule">cibuild1</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
  <span class="token key atrule">needs</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&quot;cibuild&quot;</span><span class="token punctuation">]</span>
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;开始执行$<span class="token punctuation">{</span>TEST_ENV<span class="token punctuation">}</span><span class="token punctuation">...</span>&quot;

<span class="token key atrule">cibuild2</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
  <span class="token key atrule">needs</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&quot;cibuild1&quot;</span><span class="token punctuation">]</span>
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;开始执行$<span class="token punctuation">{</span>TEST_ENV<span class="token punctuation">}</span><span class="token punctuation">...</span>&quot;

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><p><img src="/img/image-20220620125547857.png" alt="image-20220620125547857"></p> <p><img src="/img/image-20220620142404712.png" alt="image-20220620142404712"></p> <h5 id="rules-流程控制"><a href="#rules-流程控制" class="header-anchor">#</a> rules 流程控制</h5> <p>通常，我们在编写流水线的时候，我们需要一些判断，例如：go语言的部署和Python语言的部署完全不一样，这个时候我们就需要使用流程控制。</p> <table><thead><tr><th>字符</th> <th>值</th> <th>解释</th></tr></thead> <tbody><tr><td>if</td> <td>=</td> <td>等于</td></tr> <tr><td></td> <td>!=</td> <td>不等于</td></tr> <tr><td></td> <td>=~</td> <td>正则</td></tr> <tr><td></td> <td>&amp;&amp;</td> <td>并且</td></tr> <tr><td></td> <td>||</td> <td>或者</td></tr> <tr><td>changes</td> <td></td> <td>文件变更时条件为真</td></tr> <tr><td>exists</td> <td></td> <td>文件存在时条件为真</td></tr> <tr><td>allow_failure</td> <td></td> <td>允许作业在不停止管道的情况下失败</td></tr> <tr><td>variable</td> <td></td> <td>重新定义变量的值</td></tr></tbody></table> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">stages</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> build
  
<span class="token comment"># 全局变量</span>
<span class="token key atrule">variables</span><span class="token punctuation">:</span>
  <span class="token key atrule">MAIN</span><span class="token punctuation">:</span> cibuild

<span class="token key atrule">cibuild</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;开始执行$<span class="token punctuation">{</span>MAIN<span class="token punctuation">}</span><span class="token punctuation">...</span>&quot;
  <span class="token key atrule">allow_failure</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
  <span class="token key atrule">rules</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> <span class="token key atrule">if</span><span class="token punctuation">:</span> $MAIN == &quot;cibuild&quot;

<span class="token key atrule">cibuild1</span><span class="token punctuation">:</span>
  <span class="token key atrule">stage</span><span class="token punctuation">:</span> build
  <span class="token key atrule">tags</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> build
  <span class="token key atrule">script</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> echo &quot;开始执行<span class="token punctuation">...</span>&quot;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div></div></div>  <div class="page-edit"><div class="edit-link"><a href="https://github.com//edit/master/docs/05.DevOps/02.gitlab/02.GitLab.md" target="_blank" rel="noopener noreferrer">编辑</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2022/06/24, 12:24:14</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/30f9ff/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">01、Git</div></a> <a href="/pages/4e044c/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">Jenkins入门</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/30f9ff/" class="prev">01、Git</a></span> <span class="next"><a href="/pages/4e044c/">Jenkins入门</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/894626/"><div>
            企业级流水线的两种部署场景
            <!----></div></a> <span class="date">06-23</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/bc4b74/"><div>
            Jenkins集成各种工具
            <!----></div></a> <span class="date">06-23</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/c6f51e/"><div>
            Jenkins流水线语法
            <!----></div></a> <span class="date">06-23</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:chenyangqit@163.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://juejin.cn/user/730513894553032/course" title="掘金" target="_blank" class="iconfont icon-juejin"></a><a href="/img/weixin.jpg" title="微信" target="_blank" class="iconfont icon-weixin"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2019-2022
    <span>小阳爱技术 | <a href="https://blog.abck8s.com" target="_blank">MIT License</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.9f33dad1.js" defer></script><script src="/assets/js/2.336839c5.js" defer></script><script src="/assets/js/26.51a93ad7.js" defer></script>
  </body>
</html>
